<template>
  <div class="component">
    <app-header title="测试" :needBack="true"></app-header>
    <div class="section">
      <h3 class="section-title">报表一</h3>
      <div class="section-body">
        <div class="chart" ref="chart01"></div>
      </div>
    </div>
    <div class="section">
      <h3 class="section-title">报表二</h3>
      <div class="section-body">
        <div class="chart" ref="chart02"></div>
      </div>
    </div>
  </div>
</template>
<script>
  import AppHeader from '@/components/common/AppHeader'
  import Echarts from '@/assets/js/Echarts'
  import echarts from 'echarts'
  export default {
    data () {
      return {

      }
    },
    methods: {
      renderChart01 () {
        const option = {
          xAxis:[
            {
              type: 'category',
              data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
              axisTick: {
                alignWithLabel: true
              }
            }
          ],
          yAxis: [
            {
              type : 'value'
            }
          ],
        }
        const chart = new Echarts(this.$refs.chart01).bar(option)
        chart.showLoading()
        const series = [
          {
            name:'直接访问',
            type:'bar',
            barWidth: '60%',
            data:[10, 52, 200, 334, 390, 330, 220]
          }
        ]
        setTimeout(() => {
          chart.setOption({
            series
          })
          chart.hideLoading()
        }, 2000)
      },
      renderChart02 () {
        const chart = echarts.init(this.$refs.chart02)
        const option = {
          color: ['#3398DB'],
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: [
            {
              type: 'category',
              data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
              axisTick: {
                alignWithLabel: true
              }
            }
          ],
          yAxis: [
            {
              type : 'value'
            }
          ],
          series : [
            {
              name:'直接访问',
              type:'bar',
              barWidth: '60%',
              data:[10, 52, 200, 334, 390, 330, 220]
            }
          ]
        }
        chart.setOption(option)
      }
    },
    mounted () {
      this.renderChart01()
      this.renderChart02()
    },
    components: {
      AppHeader
    }
  }
</script>
<style lang="less" scoped>
  .chart {
    width: 100%;
    height: 60vh;
  }
</style>
